package de.bensoft.jrail.client;

import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.apache.log4j.Logger;

import de.bensoft.jrail.client.common.FormCreator;
import de.bensoft.jrail.client.common.FormCreatorResult;
import de.bensoft.jrail.client.common.SceneCreatorResult;
import de.bensoft.jrail.client.common.StartupScene;
import de.bensoft.jrail.client.ui.mainform.MainFormController;

public class MainSceneCreator {

	private static Logger LOG = Logger.getLogger(MainSceneCreator.class);
	
	@Inject 
	private FormCreator fCreator;
	
	public void launchApplication(@Observes @StartupScene Stage s) {
		LOG.info("Starting Application");
		
		SceneCreatorResult res = fCreator.createScene(MainFormController.class);
		s.setScene(res.getScene());
		s.setTitle("jRAIL");
		s.show();
		
		s.setOnCloseRequest(new EventHandler<WindowEvent>() {
			public void handle(WindowEvent arg0) {
				System.exit(1);
			}	
		});
	}
}
